package yto.freemarker.java8.lambda;


import org.junit.Test;
import yto.freemarker.java8.entity.Employee;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;

/**
 * 第一个入门的demo
 *
 * @author dongxing
 * @create 2018-06-13 18:37
 **/
public class Demo1 {

    List<Employee> list = Arrays.asList(new Employee("Zhansgan", 10, 200.0),
            new Employee("lisi", 20, 300.0),
            new Employee("wangwu", 30, 400.0),
            new Employee("zhangliu", 40, 500.0)
    );


    @Test
    public void test1() {
        Comparator<Integer> comparator = (x, y) -> Integer.compare(x, y);

        TreeSet<Integer> set = new TreeSet(comparator);
    }

    @Test
    public void test2() {
        //遍历集合
        list.forEach(System.out::println);
    }

    @Test
    public void test3() {
        //取出想要符合条件的数据
        list.stream()
                //添加过滤的条件
                .filter((e) -> e.getSolary() >= 300)
                //取出前几条数据
                .limit(2)
                //遍历打印
                .forEach(System.out::println);

        System.out.println("------------------");

        //取出集合中所有人的名字
        list.stream()
                .map(Employee::getName)
                .forEach(System.out::println);

    }


}
